package com.woniuxy.controller;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.entity.Absence;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.ResponseResult;
import com.woniuxy.service.AbsenceService;

import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;


@RestController
public class AbsenceController {
   @Resource
    AbsenceService absenceService;
 @PostMapping("/absence/{pageIndex}/{pageSize}")
 public ResponseResult<PageBean<Absence>> getAllAbsence(@RequestBody Absence absence, @PathVariable("pageIndex")int pageIndex,
                                                        @PathVariable("pageSize")int pageSize){
     ResponseResult<PageBean<Absence>>responseResult;
     try {

         PageBean<Absence>pageBean= absenceService.getAllAbsence(absence, pageIndex, pageSize);
    responseResult=new ResponseResult<>(200, "ok", pageBean);
 return responseResult;
     }catch (serviceException e){
         responseResult = new ResponseResult<>(500, e.getMessage(), null);
         return responseResult;

     }



 }
@PutMapping("/absence")
    public void  upSence(@RequestBody Absence absence){

     absenceService.upAbsence(absence);



}
@PostMapping("/absence")
public ResponseResult addAbsence(@RequestBody Absence absence){
try{


    absenceService.addAbsence(absence);

    return  new ResponseResult(200, null, "ok");
}catch(Exception ex){



            return  new ResponseResult(200, null, ex.getMessage());

        }


}


}
